<template>
  <div class="app-container">
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <span style="display:inline-block;line-height:28px">账套信息</span>
        <el-button v-if="isShowBuild" v-permiss="['701010']" type="primary" round size="small" style="float:right" @click="handleAdd">建账</el-button>
      </div>
      <el-table v-loading="loading" :data="tableData">
        <el-empty slot="empty" :image-size="120" />
        <el-table-column label="账套名称" align="center" prop="bookName" />
        <el-table-column label="科目体系" align="center" prop="coaHierarchyCode" />
        <el-table-column label="启用期间" align="center" prop="enablePeriodCode" />
        <el-table-column label="科目级次" align="center" prop="coaLevel" />
        <el-table-column label="科目编码规则" align="center" prop="codingRule" />
        <el-table-column label="默认增值税率" align="center">
          <template slot-scope="{row}">
            <span>{{ row.defaultTaxRate && row.defaultTaxRate * 100 + '%' }}</span>
          </template>
        </el-table-column>
        <el-table-column label="备注" align="center" prop="remarks" />
        <el-table-column label="操作" align="center" width="160">
          <template>
            <el-button v-permiss="['701020']" type="primary" round size="small" @click="handleCompile">编辑</el-button>
            <el-button v-permiss="['701050']" type="danger" round size="small" @click="resetAcc">重置</el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-card>
  </div>
</template>
<script>
import { checkBookNum, getAccount, resetAccount } from '@/api/user'
export default {
  name: 'Book',
  data() {
    return {
      dialogStatus: 'create',
      tableData: [],
      loading: false,
      isShowBuild: false
    }
  },
  mounted() {
    this.getData()
    checkBookNum().then(res => {
      if (res.data.errorCode === '0') {
        this.isShowBuild = res.data.data || false
      }
    })
  },
  methods: {
    resetAcc() {
      this.$confirm('账套的所有初始数据,包括科目,科目余额表等将全部被重置,确定要重置这个账套吗?', '警告', {
        confirmButtonText: '确定',
        closeOnClickModal: false,
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        resetAccount().then(res => {
          if (res.data.errorCode === '0') {
            this.$message.success(res.data.msg)
            this.$store.dispatch('user/logout').then(() => {
              this.$router.replace('/login')
            })
          }
        })
      })
    },
    handleCompile() {
      this.$router.push('/init/modifybook')
    },
    handleAdd() {
      var txt = '科目体系、本位币、启用期间不可再更改；科目如果已被使用,则该科目的数量核算和辅助核算选择不可再更改。'
      this.$confirm(txt, '提示', {
        dangerouslyUseHTMLString: true,
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$router.push('/init/buildbook')
      }).catch(() => {
        console.log('取消')
      })
    },
    getData() {
      this.loading = true
      getAccount().then(res => {
        this.loading = false
        if (res.data.errorCode === '0') {
          this.tableData = res.data.data || []
        }
      })
    }
  }
}
</script>
<style lang="scss" scoped>
.panel-group {
    .card-panel-col {
        margin-bottom: 32px;
    }
}

/deep/.el-card__header {
    padding: 10px 15px
}

/deep/.el-card__body {
    padding: 10px 20px 15px;
}
/deep/ .el-input__inner{
    padding: 0 5px;
}
/deep/.el-form-item {
    margin-bottom: 16px;
}
</style>
